package mammuthus.template.hadoop

import mammuthus.template.TemplateProcessor
import mammuthus.protocal.WriteFileTaskResponse
import mammuthus.tool.TemplateTool
import mammuthus.master.Master

/**
 * 5/5/15 WilliamZhu(allwefantasy@gmail.com)
 */
class MapredSiteProcessor(master: Master) extends TemplateProcessor {

  case class NameNode(host: String, rpcPort: Int = 9000, httpPort: Int = 50070)


  override def process(fileName: String, targetFilePath: String, params: Map[String, AnyRef]): List[WriteFileTaskResponse] = {
    val appName = params("appName").asInstanceOf[String]
    val app = params.getOrElse("app",appName)
    val mapred_system_dir = params.getOrElse("dataNodeDataBaseDir","/data/2").asInstanceOf[String].
      split(",").map(f => f + s"/${appName}/mr/mapred_sys").mkString(",")

    val mapred_local_dir = params.getOrElse("dataNodeDataBaseDir","/data/2").asInstanceOf[String].
      split(",").map(f => f + s"/${appName}/dfs/tmp").mkString(",")

    val configStr = TemplateTool.render(s"/template/app/$app/$fileName", Map(
      "mapred_system_dir" -> mapred_system_dir,
      "mapred_local_dir" -> mapred_local_dir
    ))

    val slaves = params("slaves").asInstanceOf[String]

    master.writeFile(slaves, configStr, targetFilePath, false)
  }
}
